package com.zjm.filter.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author ZJM
 * @date 2024/4/26 22:06
 */
@WebServlet("/login")
public class LoginServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        if (username.equals("zjm") && password.equals("123456")) {
            req.getSession().setAttribute("user", username);
            resp.getWriter().write("登录成功");
        } else {
            req.getRequestDispatcher("/login.jsp").forward(req, resp);
        }
    }
}
